<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="zh-cn">
<head>
<meta charset="utf-8" />
<meta name="viewport"
	content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
<link href="css/app-back.css" rel="stylesheet" />
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/underscore-min.js"></script>
<script type="text/javascript" src="js/backbone-min.js"></script>
</head>
<body>
	<div class="container">
		<!--bg img-->
		<img src="images/bg_back.jpg" class="bg">
		<div class="board" id="loginPart">
			<h3>
				Log In <small style="color: #aaa;">for Admin</small>
			</h3>
			<div class="login-item">
				<p>Email Address:</p>
				<input type="text" name="email">
			</div>
			<div class="login-item">
				<p>Password:</p>
				<input type="password" name="password">
			</div>
			<p style="text-align: center;">
				<span class="btn" id="submit">Confirm</span><span
					style="color: red; margin-left: 30px" id="error"></span>
			</p>
		</div>
	</div>
	<script type="text/javascript">
	var USER = Backbone.Model.extend({
        defaults:{
            userEmail:"email",
            userPassword:"password",
        },
        initialize:function(){
            this.on("invalid",function(model,error){
                $("#submit").text("Confirm");
                model.saving = false;
                model.logError(error);
            });
        },
        validate:function(attrs){
           var emailTest  = /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;
           if( emailTest.test(attrs.userEmail)===false ){
                $("input[name='email']").focus();
                return "*请输入正确的邮箱地址";
           }
           if(attrs.userPassword=="" || attrs.userPassword.length<6){
               $("input[name='password']").focus();
               return "*密码长度不能小于6位";
           }
        },
        url:"/adminloginAction",
        logError:function(msg){
            var m = msg || "";
            $("#error").text(m);
        },
        saving:false
    });
    var VIEW = Backbone.View.extend({
       el:$("#loginPart"),
       events:{
           "click #submit":"login"
       },
       login:function(){
           this.model.logError();
           var _email = $("input[name='email']").val() ||　"";
           var _password = $("input[name='password']").val() ||　"";
           this.model.set({userEmail:_.escape(_email)});
           this.model.set({userPassword:_.escape(_password)});
           if(this.model.saving==true){
               return ;
           }
           this.model.saving = true;
           $(event.target).text("Ing...");
           //response  {status:0,href:""} 
           this.model.save(null,{
               success:function(model,response){
                   if( response.status == 0 ){
                       model.logError("*用户名或密码不正确");
                   }
                   else{
                       location.href = "/personaladmin.jsp";
                   }
                   model.saving = false;
                   $("#submit").text("Confirm");
               },
               error:function(model,response){
                  model.logError("未知错误，刷新后重试");
                  model.saving = false;
                  $("#submit").text("Confirm");
               },
               wait:true
           });
       }
    });
    var user_infor = new USER();
    var login_view = new VIEW({model:user_infor});
	</script>
</body>
</html>